/**
 * 
 */
package oop.ex2.filters;
import java.util.HashMap;
/**
 * Factory of all filters.
 */
public class FilterFactory {
	//***********************************************************************
	//  Data members :                                                      *
	//***********************************************************************
	private HashMap<String, Filter> _map;
	//***********************************************************************
	//  Methods :                                                           *
	//***********************************************************************
	/**
	 * Constructs a new filter factory.
	 */
    public FilterFactory() {
        initializeHashMap();
    }

	/**
	 * Initializes the filter map.
	 */
	private void initializeHashMap() {
	    _map = new HashMap<String, Filter>();
	    _map.put("MODIFIED_BEFORE", 
	            new CompareDateFilter(ComparableFilter.SMALLER) );
	    _map.put("MODIFIED_AFTER", 
	            new CompareDateFilter( ComparableFilter.BIGGER ) );
	    _map.put("MODIFIED_ON", 
	            new CompareDateFilter( ComparableFilter.EQUALS ));
	    _map.put("SIZE_MORE_THAN", 
	            new CompareSizeFilter( ComparableFilter.BIGGER ));
	    _map.put("SIZE_LESS_THAN", 
	            new CompareSizeFilter(ComparableFilter.SMALLER));
	    _map.put("SIZE_EQUAL_TO", 
	            new CompareSizeFilter(ComparableFilter.EQUALS));
	    _map.put("TEXT_IN_FILE", new FileTextFilter());
	    _map.put("BYTE_IN_FILE", new BinaryFileFilter());
	    _map.put("SUBDIR_WILDCARD", new SubDirWildcardFilter());
	    _map.put("FILE_WILDCARD", new FileNameWildCardFilter());
	    _map.put("SUBDIR_DEPTH", new SubdirDepthFilter());
	}
	/**
	 * Returns a filter object.
	 * @param expression Filter's name to be returned.
	 * @return A filter object.
	 */
	public Filter getInstance(String expression) {
	    return _map.get(expression);
	}
	
}
